/**
 * Class representing some common statistical functions
 */
package common;

import java.util.ArrayList;

/**
 * @author vladimir
 * 
 */
public class Stat {

	public static int corLen(ArrayList<Double> input) {
		// /*
        // Definition from Many body physics book
        // \tau_{int} = 1/2 + \sum_{t=1}^N C(t) (1 - t / N)
        //
		// */

		double[] result = new double[input.size()];
		for (int i = 0; i < input.size(); i++) {
			result[i] = input.get(i);
		}

		Series tS = new Series(result);
		double[] data = tS.autocorrelation;

        double resultValue = 1/2;

        int upperValue = Math.min(data.length, 1000);
		for (int i = 1; i < upperValue; i++) {
			resultValue += data[i] * (1 - i / upperValue);
        }

        if (resultValue < 1){
            return 1;
        }
		return (int) resultValue;
	}

	/*
	 * returns sum of the array
	 */
	public static double sum(int[] is) {
		double result = 0;
		for (double value : is) {
			result += value;
		}
		return result;
	}

}
